package com.woniu.register.controller;

import com.github.pagehelper.PageInfo;
import com.woniu.common.util.Result;
import com.woniu.common.util.ResultVO;
import com.woniu.register.dto.DirectoryLiDTO;
import com.woniu.register.service.DirectoryService;
import com.woniu.register.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author ：lgy
 * @description：登记薄控制层
 * @date ：2022/12/7 17:23
 */
@RestController
@RequestMapping("directory")
public class DirectoryController {
    @Autowired
    private DirectoryService directoryService;
    @PostMapping("selAll")
    public ResultVO selAll(@RequestBody DirectoryLiDTO directoryLiDTO){
        List<DirectoryLiVO> list = directoryService.selectAllDirectory(directoryLiDTO);
        PageInfo<DirectoryLiVO> pageInfo = new PageInfo<DirectoryLiVO>(list);
        return ResultVO.success("查询成功",pageInfo);
    }
    @PostMapping("selFm/{id}")
    public Result selFm(@PathVariable("id") Long id){
        DirectoryLiVO directoryLiVO = directoryService.selectDirectoryNumAndHigherMound(id);
        return Result.ok().data("higherMound",directoryLiVO.getHigherMound()).data("directoryNum",directoryLiVO.getDirectoryNum());
    }
    @PostMapping("selJbzk/{id}")
    public Result selJbzk(@PathVariable("id") Long id){
        JbzkVO jbzkVO = directoryService.selectJbzkByDirectoryId(id);
        return Result.ok().data("jbzkVO",jbzkVO);
    }
    @PostMapping("selSyq/{id}")
    public Result selSyq(@PathVariable("id") Long id){
        Map<String, Object> map = directoryService.selectSyqByDirectoryId(id);
        return Result.ok().data("map",map);
    }
    @PostMapping("selXfdy/{id}")
    public Result selXfdy(@PathVariable("id") Long id){
        XfdyVO xfdyVO = directoryService.selectXfdyByDirectoryId(id);
        return Result.ok().data("xfdyVO",xfdyVO);
    }
    @PostMapping("selZjdy/{id}")
    public Result selZjdy(@PathVariable("id") Long id){
        ZjdyVO zjdyVO = directoryService.selectZjdyByDirectoryId(id);
        return Result.ok().data("zjdyVO",zjdyVO);
    }
    @PostMapping("selYgdj/{id}")
    public Result selYgdj(@PathVariable("id") Long id){
        YgdjVO ygdjVO = directoryService.selectYgdjByDirectoryId(id);
        return Result.ok().data("ygdjVO",ygdjVO);
    }
    @PostMapping("selCfdj/{id}")
    public Result selCfdj(@PathVariable("id") Long id){
        CfdjVO cfdjVO = directoryService.selectCfdjByDirectoryId(id);
        return Result.ok().data("cfdjVO",cfdjVO);
    }
    @PostMapping("selYydj/{id}")
    public Result selYydj(@PathVariable("id") Long id){
        YydjVO yydjVO = directoryService.selectYydjByDirectoryId(id);
        return Result.ok().data("yydjVO",yydjVO);
    }

    @PostMapping("add")
    public Result add() {
        int i = directoryService.insertDirectory();
        int directoryId = directoryService.selectId();
        if (i > 0) {
            return Result.ok().data("新增登记簿成功",directoryId);
        } else {
            return Result.error();
        }
    }
    @PutMapping("updateState/{directory}")
    public Result updateDirectoryState(@PathVariable("directory") String directoryNum){
        int i = directoryService.updateStatue(directoryNum);
        return i == 1 ? Result.ok("灭籍成功！") : Result.error("灭籍失败");
    }

}
